﻿<UserControl x:Class="Xinnos.Lca.Yacht.Analyzer.View.WorkBreakdownStructureTreePanel"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:this="clr-namespace:Xinnos.Lca.Yacht.Analyzer.View" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.CommandBindings>
        <CommandBinding Command="New" CanExecute="OnCanExecuteNewCommand" Executed="OnExecuteNewCommand" />
        <CommandBinding Command="Replace" CanExecute="OnCanExecuteReplaceCommand" Executed="OnExecuteReplaceCommand" />
        <CommandBinding Command="Delete" CanExecute="OnCanExecuteRemoveCommand" Executed="OnExecuteRemoveCommand" />
        <CommandBinding Command="Refresh" CanExecute="OnCanExecuteComponentsCommand" Executed="OnExecuteComponentsCommand" />
    </UserControl.CommandBindings>
    <Grid>
        <TreeView x:Name="treeViewStructure" ItemsSource="{Binding WorkBreakdownStructures}" SelectedItemChanged="OnWorkBreakdownStructureSelectedItemChanged">
            <TreeView.ContextMenu>
                <ContextMenu>
                    <MenuItem Command="New" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ContextMenu}}}" />
                    <MenuItem Command="Replace" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ContextMenu}}}" />
                    <MenuItem Command="Delete" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ContextMenu}}}" />
                    <MenuItem Command="Refresh" CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ContextMenu}}}" />
                </ContextMenu>
            </TreeView.ContextMenu>
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate DataType="{x:Type this:WorkBreakdownStructureViewModel}" ItemsSource="{Binding Children}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <CheckBox Grid.Column="0" Margin="5,0,5,0"  IsChecked="{Binding Selected,UpdateSourceTrigger=PropertyChanged}" Visibility="Collapsed" />
                        <TextBlock Grid.Column="1" Margin="5,0,5,0" Text="{Binding Name}" />
                    </Grid>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>
    </Grid>
</UserControl>
